<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class WisemanGoods extends Model
{
    protected function getPriceAttr($val){
        return round($val / 100,2);
    }

    public static function goods($author_id, $currentPage, $perPage){
        $start = date("Y-m-d H:i:s",strtotime("-1 month"));
        $end = date("Y-m-d H:i:s",strtotime("-1 day"));
        $data = self::field('title,cover,product_id,sales,view,price,author_id,date')
            ->where(['author_id'=>$author_id])
            ->where('date','between',"{$start},{$end}")
            ->paginate(['page'=>$currentPage,'list_rows'=>$perPage]);
        $nData = [];
        if($data){
            $nData = $data->toArray();
            foreach($nData['data'] as $k=>$v){
                $nData['data'][$k]['title'] = cut_str($v['title'], 10);
            }
        }
        return $nData;
    }
}
